# encoding:utf-8
import threading, time, ctypes
from auto_measure import run, reset_device
from deviceConnect import initWebSocket, get_data, send_msg

class thread_with_exception(threading.Thread):
  def __init__(self, target):
    super(thread_with_exception, self).__init__(target=target)
  
  def kill(self):
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.ident), ctypes.py_object(SystemExit))


def test():
  while True:
    time.sleep(1)
    print('running')


device_t = None


def device_run():
  global device_t
  device_t = thread_with_exception(run)
  device_t.start()


def device_reset():
  global device_t
  if device_t:
    device_t.kill()
    device_t.join()
  reset_measure()
  

if __name__ == "__main__":
    print("begin run main thread")
    initWebSocket(device_run, device_reset)
    

